#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#define MAX 1024
#define ARGC 64
#define SEP " "

int split(char *commandstr, char *argv[]){
    assert(commandstr);
    assert(argv);

    argv[0] = strtok(commandstr, SEP);
    if(argv[0] == NULL)
        return -1;
    int i = 1;
    while((argv[i++] = strtok(NULL, SEP)));
    return 0;
}

int main(){
    while(1){
        char commandStr[MAX] = {0};
        char* argv[ARGC] = {NULL};
        printf("[Lu@curPath]# ");
        fflush(stdout);
        char* s = fgets(commandStr, sizeof(commandStr), stdin);
        assert(s);
        (void)s;
        //将\n去掉
        commandStr[strlen(commandStr) - 1] = '\0';
        int n = split(commandStr, argv);
        if(n != 0)
            continue;
        
        pid_t id = fork();
        assert(id >= 0);
        (void)id;

        if(id == 0){
            execvp(argv[0], argv);
            exit(1);
        }

        int status = 0;
        waitpid(id, &status, 0);
    }
}